package main

import (
	"fmt"
	"log"

	"eeetest/xxx"

	"github.com/bytedance/gopkg/util/gctuner"
	"github.com/goccy/go-json"
	"github.com/gofiber/fiber/v3"
)

func main() {
	// Get mem limit from the host machine or cgroup file.
	limit := uint64(4 * 1024 * 1024 * 1024)
	threshold := limit / 10 * 7

	gctuner.Tuning(threshold)
	xxx.OpenDb()
	defer xxx.Db.Close()
	app := fiber.New(fiber.Config{
		ErrorHandler: func(c fiber.Ctx, err error) error {
			return c.Status(fiber.StatusBadRequest).JSON(xxx.GlobalErrorHandlerResp{
				Success: false,
				Message: err.Error(),
			})
		},
		JSONEncoder: json.Marshal,
		JSONDecoder: json.Unmarshal,
	})
	app.Get("/", xxx.IndexHandler)
	app.Get("/foo", xxx.FooHandler)
	app.Get("/barget/:key", xxx.BarGetHandler)
	app.Get("/barget/:key/:val", xxx.BarPutHandler)
	log.Fatal(app.Listen(":8080"))
	fmt.Println("xxxxx")
}
